package com.example.leetdemo.process;

import java.util.Arrays;
import java.util.function.IntSupplier;
import java.util.stream.IntStream;

public class Solution475 {

    public int findRadius(int[] houses, int[] heaters) {
        int end = Math.max(houses[houses.length - 1], heaters[heaters.length - 1]);
        int maxLength = 0;
        for (int i = 1; i < heaters.length; i++) {
            maxLength = Math.max(heaters[i] - heaters[i - 1], maxLength);
        }
        maxLength = Math.max(maxLength, Math.abs(end - heaters[heaters.length - 1]));
        int[] temp = new int[end];
        int[] house = new int[end];
        for (int i = 0; i < houses.length; i++) {
            house[houses[i] - 1] = 1;
        }
        for (int i = 0; i < maxLength + 1; i++) {
            Arrays.fill(temp, 0);
            for (int j = 0; j < heaters.length; j++) {
                int p = heaters[j] - 1;
                if (p - i >= 0) {
                    Arrays.fill(temp,  p - i, p + 1, 1);
                } else  {
                    Arrays.fill(temp,  0, p + 1, 1);
                }
                if (p + i < end) {
                    Arrays.fill(temp,  p, p + i + 1, 1);
                } else {
                    Arrays.fill(temp, p, end, 1);
                }
            }
            boolean result = true;
            for (int j = 0; j < end; j++) {
                if (house[j] != temp[j] && house[j] == 1) {
                    result = false;
                }
            }
            if (result) {
                return i;
            }
        }
        return maxLength;
    }

    public static void main(String[] args) {
        Solution475 solution475 = new Solution475();
//        System.err.println(solution475.findRadius(new int[]{1,5}, new int[]{10}));
        System.err.println(percentageLetter("aaab", 'a'));


    }


    public static int percentageLetter(String s, char letter) {
        int a = s.length();
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            count += s.charAt(i) == letter ? 1 : 0;
        }
        return (count * 100) / a ;
    }
}
